package com.erp.servlet;

import com.erp.bean.Department;
import com.erp.bean.Emp;
import com.erp.bean.Role;
import com.erp.service.DepartmentService;
import com.erp.service.EmpService;
import com.erp.service.RoleService;
import com.erp.service.impl.DepartmentServiceImpl;
import com.erp.service.impl.EmpServiceImpl;
import com.erp.service.impl.RoleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author lyb
 * 员工列表控制器
 */
@WebServlet("/emplist.action")
public class EmpListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建员工业务逻辑对象
        EmpService empService = new EmpServiceImpl();
        DepartmentService departmentService = new DepartmentServiceImpl();
        RoleService roleService = new RoleServiceImpl();

        List<Department> departments = departmentService.findAll();
        System.out.println(departments);
        req.setAttribute("departments",departments);

        List<Role> roles = roleService.findAll();
        System.out.println(roles);
        req.setAttribute("roles",roles);

        //将查询到的对象放入集合中
        List<Emp> list = empService.finAll();
        //将集合放入作用域中
        req.setAttribute("list",list);
        //转发到员工列表界面
        req.getRequestDispatcher("emplist.jsp").forward(req,resp);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
